/*
XMLRPC client for GWT
Copyright (C) 2006

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

*/

package com.fredhat.gwt.xmlrpc.client;

/**
 * This class is an extension of java.util.Date that does not use
 * milliseconds.  This is because the ISO8601 date format does not 
 * use milliseconds.
 * 
 * @author Fred Drake
 *
 */
public class Date extends java.util.Date {
	
	/**
	 * Returns the same value as java.util.Date.getTime() except
	 * the last three places are always zero (to indicate a perfectly
	 * even second)
	 */
	public long getTime() {
		return (super.getTime()/1000)*1000;
	}

	public int hashCode() {
		final int PRIME = 31;
		int result = super.hashCode();
		result = PRIME * result + super.getDay();
		result = PRIME * result + super.getHours();
		result = PRIME * result + super.getMinutes();
		result = PRIME * result + super.getMonth();
		result = PRIME * result + super.getSeconds();
		result = PRIME * result + super.getYear();
		return result;
	}
	
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (!super.equals(obj))
			return false;
		if (!(obj instanceof Date))
			return false;
		final Date other = (Date) obj;
		if (super.getDay() != other.getDay())
			return false;
		if (super.getHours() != other.getHours())
			return false;
		if (super.getMinutes() != other.getMinutes())
			return false;
		if (super.getMonth() != other.getMonth())
			return false;
		if (super.getSeconds() != other.getSeconds())
			return false;
		if (super.getYear() != other.getYear())
			return false;
		return true;
	}
	
}
